Skip to content

Split components/layers.py into focused modules - #922

Merged
sevmag merged 18 commits into
graphnet-team:mainfrom
sevmag:refactor/split-components-layers
Sep 11, 2026
Merged

sevmag merged 18 commits into
graphnet-team:mainfrom
sevmag:refactor/split-components-layers

Conversation

@sevmag

@sevmag sevmag commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

components/layers.py had grown to ~1000 lines holding three unrelated families of layers. This PR splits it into focused modules, one class per commit, with no behavioral changes — every class body is moved verbatim — and removes layers.py at the end:

  • components/edge_convolutions.py — the EdgeConv family: DynEdgeConv, EdgeConvTito, DynTrans
  • components/attention_blocks.py — dense transformer blocks: DropPath, Mlp, Attention_rel, Block_rel, Block
  • components/grit_layers.py — the GRIT graph-transformer family: GritSparseMHA, GritTransformerLayer, SANGraphHead (named grit_layers to avoid clashing with the GritTransformer model in models/gnn/grit.py)

All in-repo consumers (dynedge, dynedge_jinst, dynedge_kaggle_tito, particlenet, icemix, grit) import from the new locations.

⚠️ Breaking change

graphnet.models.components.layers no longer exists. External code importing from it must switch to the dedicated modules. Saved ModelConfig YAMLs are unaffected when they reference classes by bare name, but configs embedding the full path (!class graphnet.models.components.layers <Name> entries) must be re-saved against the new locations.

Structure

Each commit moves exactly one class (or updates one consumer group) and leaves the tree green — the full pre-commit suite (black, flake8, docformatter, pydocstyle, mypy) passes on every commit, so the branch stays bisectable. The intermediate commits route consumers through re-exports in layers.py; the final commit deletes it.

🤖 Generated with Claude Code

https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9

sevmag and others added 18 commits September 9, 2026 22:06
Makes the module's public API explicit for star imports and linters.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9
Start a dedicated module for the EdgeConv family of graph convolution
layers; components.layers re-exports the name so existing imports and
saved model configs keep working.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9
The EdgeConv family (DynEdgeConv, EdgeConvTito, DynTrans) is now
complete in its own module.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9
Start a dedicated module for the dense transformer building blocks;
components.layers re-exports the name so existing imports and saved
model configs keep working.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9
The dense transformer blocks (DropPath, Mlp, Attention_rel, Block_rel,
Block) are now complete in their own module.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9
Start a dedicated module for the GRIT graph-transformer layers; the
name avoids clashing with the GritTransformer model in models/gnn/grit.
components.layers re-exports the name so existing imports and saved
model configs keep working.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9
layers.py now only re-exports; all layer implementations live in
dedicated modules.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9
All layer classes are importable only from their dedicated modules
(edge_convolutions, attention_blocks, grit_layers). Saved model
configs that reference graphnet.models.components.layers by full path
must be re-saved against the new locations.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9
The module imports cleanly so that pkgutil-based module scans (the
ModelConfig class-namespace build imports every graphnet submodule)
keep working, but any attribute access — including
`from ...layers import X` and full-path `!class` references in saved
configs — raises with a pointer to the class's new module.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013B53eM2fgkivj8xxVnhjQ9
@sevmag
sevmag force-pushed the refactor/split-components-layers branch from 1f9a58a to df16393 Compare September 10, 2026 20:39
@sevmag
sevmag merged commit b4baef4 into graphnet-team:main Sep 11, 2026
12 checks passed
@sevmag
sevmag deleted the refactor/split-components-layers branch September 11, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants